clear all; close all;warning('off','all');clc;
str=strcat('C:\Users\QCH\Desktop'); %%%%%change when use
% str_read=strcat(str,'PIV_output\'); %%%%%change when use
% str_write=strcat(str,'选定瞬态\');
str_read = 'C:\Users\QCH\Desktop\PIVlab_out_011.bmp'
str_write = 'C:\Users\QCH\Desktop\
row1=552;
col1=1392;
row=552;
col=1392;


global str a b r1 r2 a_inner b_inner a_outer b_outer

a=-715;b=650;r1=860;r2=1214;   
% a=-730;b=700;r1=883;r2=1250; 
a_inner = a;   
a_outer = a;
% b_inner = b;%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% b_outer = b;
b_inner = b + 30; %左侧三 
b_outer = b + 30;%左侧三
r1 = r1 + 16;%左侧三
r2 = r2 + 16;%左侧三
first_bmp=155;last_bmp=155;%161;

for current_bmp = first_bmp:last_bmp
    if current_bmp<10
         str_bmp = strcat (str_read,'PIVlab_out_','00',int2str(current_bmp) , '.bmp'); % 连接字符串形成图像的文件名
    elseif current_bmp<100
         str_bmp = strcat (str_read,'PIVlab_out_','0',int2str(current_bmp) , '.bmp');
    elseif current_bmp<1000
         str_bmp = strcat (str_read, 'PIVlab_out_',int2str(current_bmp), '.bmp');
    else
        fprintf('CHECK1!! the SUM and serial number of Files does not match to this programme.');
    end
    rgb=imread(str_bmp);
    
    [m,n,k]=size(rgb);
    
    %把裁掉边框的部分放在rgb1中
%     PIV_a = m-28;寝室
%     PIV_b = n-19;
%     A=zeros(PIV_a,PIV_b);
%     A=uint8(A);
%     rgb1=cat(3,A,A,A);
%     for i=1:PIV_a
%         for j=1:PIV_b
%             rgb1(i,j,:)=rgb(i+12,j+8,:);%裁掉边框的部分
%         end
%     end
    PIV_a = m-21;%笔记本
    PIV_b = n-14;
    A=zeros(PIV_a,PIV_b);
    A=uint8(A);
    rgb1=cat(3,A,A,A);
    for i=1:PIV_a
        for j=1:PIV_b
            rgb1(i,j,:)=rgb(i+9,j+5,:);%裁掉边框的部分
        end
    end



    rgb1= imresize(rgb1,[row1 col1]);
    imshow(rgb1)
    %内外涂白
    a1=zeros(row,col);
    for i=1:row
        for j=1:col  
            a1(i,j)= (i-a_inner).^2+(j-b_inner).^2-r1^2;
            if a1(i,j)<=0
                rgb1(i,j,1)=255;
                rgb1(i,j,2)=255;
                rgb1(i,j,3)=255;
            end
            a1(i,j)= (i-a_outer).^2+(j-b_outer).^2-r2^2;
            if a1(i,j)>=0
                rgb1(i,j,1)=255;
                rgb1(i,j,2)=255;
                rgb1(i,j,3)=255;
            end
        end
    end
    
   
    
    
    %rgb1 内外壁涂黑
    r1_new=r1;
    r2_new=r2;
    a1=zeros(row,col);
    for i=1:row
        for j=1:col  
            a1(i,j)= (i-a_inner).^2+(j-b_inner).^2-r1_new^2;
            if (a1(i,j)<2000) && (a1(i,j)>-2000) %649 * 5pixels
                rgb1(i,j,1)=0;
                rgb1(i,j,2)=0;
                rgb1(i,j,3)=0;
            end
            a1(i,j)= (i-a_outer).^2+(j-b_outer).^2-r2_new^2;
            if ( a1(i,j)<3000) && ( a1(i,j)>-3000 )
                rgb1(i,j,1)=0;
                rgb1(i,j,2)=0;
                rgb1(i,j,3)=0;
            end
        end
    end
%     %rgb1 上方的涂黑
%     for i=1:2
%         for j=1:214 %214 174
%             rgb1(i,j,1)=0;
%             rgb1(i,j,2)=0;
%             rgb1(i,j,3)=0;
%         end
%         for j=1164:col %1164 1125
%             rgb1(i,j,1)=0;
%             rgb1(i,j,2)=0;
%             rgb1(i,j,3)=0;
%         end
%     end
%     %rgb1 左右两边的涂黑
%     for i=1:284 %284  310
%         for j=1:2
%             rgb1(i,j,1)=0;
%             rgb1(i,j,2)=0;
%             rgb1(i,j,3)=0;
%         end
%     end
%     for i=1:274%    274 246
%         for j=col-1:col
%             rgb1(i,j,1)=0;
%             rgb1(i,j,2)=0;
%             rgb1(i,j,3)=0;
%         end
%     end

 %rgb1 上方的涂黑
    for i=1:2
        for j=1:col %214 174
            a1(i,j)= (i-a_inner).^2+(j-b_inner).^2-r1^2;
            if a1(i,j)>=0
                rgb1(i,j,1)=0;
                rgb1(i,j,2)=0;
                rgb1(i,j,3)=0;
            end
        end
    end
    %rgb1 左右两边的涂黑
    for i=1:row %284  310
        for j=1:2
            a1(i,j)= (i-a_outer).^2+(j-b_outer).^2-r2^2;
            if a1(i,j)<=0
                rgb1(i,j,1)=0;
                rgb1(i,j,2)=0;
                rgb1(i,j,3)=0;
            end
        end
    end
    for i=1:row%    274 246
        for j=col-1:col
            a1(i,j)= (i-a_outer).^2+(j-b_outer).^2-r2^2;
            if a1(i,j)<=0
                rgb1(i,j,1)=0;
                rgb1(i,j,2)=0;
                rgb1(i,j,3)=0;
            end
        end
    end
    
    
    
    


% 输出
    if current_bmp<10
         str_put = strcat ('00',int2str(current_bmp) , '.bmp'); % 连接字符串形成图像的文件名
    elseif current_bmp<100
         str_put = strcat ('0',int2str(current_bmp) , '.bmp');
    elseif current_bmp<1000
         str_put = strcat (int2str(current_bmp), '.bmp');
    else
        fprintf('CHECK3!! the SUM and serial number of Files does not match to this programme.');
    end
    
    imwrite(rgb1,[str_write str_put]);
    imshow(rgb1);
    
    
end